<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/3/11
 * Time: 16:03
 * @copyright: ©2024 永州微聚 商网络科技有限公司
 * @link: https://www.weijuYunke.com
 */


namespace app\admin\controller;

use app\common\model\Menu as MenuModel;
use app\Request;

class  Menu{
    public function index(Request $request){
        $MenuModel = new MenuModel();
        $data =  $MenuModel->getMenu(array_column($request->role,'role_id'));
        return success('菜单列表',$data);
    }
    public function add(Request $request){
        $param = $request->param();
        if (empty($param['title'])){
            return error('请输入菜单名称');
        }
        $data = [
            'parentId' => $param['parentId'],
            'title' => $param['title'],
            'path' => $param['path'],
            'component' =>  $param['component'],
            'menuType' => $param['menuType'],
            'sortNumber' => $param['sortNumber'],
            'icon' => $param['icon'],
            'authority' =>  $param['authority'],
            'create_time' => date('Y-m-d H:i:s'),
        ];
        $MenuModel = new MenuModel();
        $MenuModel->insert($data);
        return success('添加成功');

    }
    public function edit(Request $request){
        $param = $request->param();
        if (empty($param['title'])){
            return error('请输入菜单名称');
        }
        $data = [
            'parentId' => $param['parentId'],
            'title' => $param['title'],
            'path' => $param['path'],
            'menuType' => $param['menuType'],
            'sortNumber' => $param['sortNumber'],
            'icon' => $param['icon'],
            'component' =>  $param['component'],
            'update_time' => date('Y-m-d H:i:s'),
            'authority' =>  $param['authority'],
        ];

        $MenuModel = new MenuModel();
        $MenuModel->where(['menuId' => $param['menuId']])->update($data);

        return success('修改成功');
    }
    public function del(Request $request){
        $param = $request->param();
        $MenuModel = new MenuModel();
        $MenuModel->where(['menuId' => $param['menuId']])->update(['deleted' => 1]);

        return success('修改成功');
    }

}

